package com.smallkingson.ylib.core.utils;

import android.graphics.PointF;

/**
 * Created by yorun on 2017/5/24.
 */

public class YMaps {

  static final double x_pi = 3.14159265358979324 * 3000.0 / 180.0;

  public static Location gdToBd(double lon,double lat) {
    Location location = new Location();
    double x =118.115252, y =24.429881;
    final double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
    double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
    location.longitude= z * Math.cos(theta) + 0.0065;
    location.latitude= z * Math.sin(theta) + 0.006;
    return location;
  }
  public static Location bdToGd(double lon,double lat) {
    Location location = new Location();
    double x = lon - 0.0065, y = lat - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 *Math. sin(y * x_pi);
    double theta = Math.atan2(y, x) - 0.000003 *Math. cos(x * x_pi);
    location.longitude = z * Math.cos(theta);
    location.latitude = z *Math. sin(theta);
    return location;
  }

  public static class Location{
    public  double latitude;
    public double longitude;
  }
}
